include 	./Makefile.select
include 	./Makefile.config



FLAGS = $(FLAGS_org)
ifeq ($(lib_type_to_build), shared)
	FLAGS = $(FLAGS_org) -fPIC
endif




SRCDIR           = ../src
OBJDIR       		 = ./objdir
TESTDIR  				 = ../tests


SYSC_LIB_HOME 	 = ../syscLib_gcc_3_4_2
ifeq ($(gcc_version), gcc_4_2_2)
	SYSC_LIB_HOME 	 = ../syscLib_gcc_4_2_2
endif

SYSTEMC_LIB_DIR  = $(SYSTEMC_HOME)/lib-$(TARGET_ARCH)
GREENREG_LIB_DIR = $(GSPM_HOME)/greenreg

OBJ_NAME = tob



INCDIR_BASIC = 		-I$(BOOST_INCL_DIR) \
		-I$(GREENSOCS_INCL_DIR) \
		-I$(GSPM_HOME) \
		-I$(GSPM_HOME)/greenreg \
	    -I$(SRCDIR) 
	    	
OBJS_BASIC =	$(OBJDIR)/main.o \
							$(OBJDIR)/tob.o \
						#$(OBJDIR)/splitter.o \
						#$(OBJDIR)/tagger.o \
						#$(OBJDIR)/kb_linker.o \
						#$(OBJDIR)/context.o \
						#$(OBJDIR)/responder.o 
	    	
			

LDFLAGS = $(LDFLAGSORG) 

INCDIR = $(INCDIR_BASIC) 

CFLAGS = $(FLAGS) $(INCDIR) 

CFLAGS_lib = $(CFLAGS) 

BUILD_OBJS = $(OBJS_BASIC)



.PHONY: clean all check

all: announce $(OBJ_NAME).exe 

announce:
	@if  ( test ! -d $(FLAG_BATCH) ); \
	 	then echo; echo "$(OBJ_NAME):"; echo; \
	 fi
	
check: announce $(OBJ_NAME).exe
	@$(VALGRIND) ./$(OBJ_NAME).exe > run.log
	@cat run.log | grep -v "stopped by user" | awk '{if($$0!="") print $$0}' > run_trimmed.log
	@cat ../results/expected.log | grep -v "stopped by user" | awk '{if($$0!="") print $$0}' > ./expected_trimmed.log
	@diff ./run_trimmed.log ./expected_trimmed.log > diff.log 2>&1;\
	if [ -s diff.log ]; then echo "***ERROR:"; cat diff.log; else echo "OK"; fi

run: announce $(OBJ_NAME).exe
	@./$(OBJ_NAME).exe


#_________________________________________________________
# build systemC simulation pac.exe
#_________________________________________________________

ifeq ($(lib_type_to_build), shared)

$(OBJ_NAME).exe: $(BUILD_OBJS) 
	$(LD) -o $@ $^ $(LDFLAGS) -L$(SYSTEMC_LIB_DIR) -lsystemcPIC 2>&1 | c++filt
	cp $(OBJ_NAME).exe $(TESTDIR)
else
$(OBJ_NAME).exe: $(BUILD_OBJS) 
	$(LD) -o $@ $^ $(LDFLAGS) -L$(SYSTEMC_LIB_DIR) -L$(GREENREG_LIB_DIR) -lgreenreg -lsystemc 2>&1 | c++filt
	cp $(OBJ_NAME).exe $(TESTDIR)
endif

	
	
#_________________________________________________________
# build CPM objs
#_________________________________________________________
#PDM Module
$(OBJDIR)/main.o: $(SRCDIR)/main.cpp 
	$(GXX) $(CFLAGS) -c $< -o $@
$(OBJDIR)/tob.o: $(SRCDIR)/tob.cpp 
	$(GXX) $(CFLAGS) -c $< -o $@
$(OBJDIR)/splitter.o: $(SRCDIR)/splitter.cpp 
	$(GXX) $(CFLAGS) -c $< -o $@
$(OBJDIR)/tagger.o: $(SRCDIR)/tagger.cpp 
	$(GXX) $(CFLAGS) -c $< -o $@
$(OBJDIR)/kb_linker.o: $(SRCDIR)/kb_linker.cpp 
	$(GXX) $(CFLAGS) -c $< -o $@
$(OBJDIR)/context.o: $(SRCDIR)/context.cpp 
	$(GXX) $(CFLAGS) -c $< -o $@
$(OBJDIR)/responder.o: $(SRCDIR)/responder.cpp 
	$(GXX) $(CFLAGS) -c $< -o $@

#_________________________________________________________
# clean up
#_________________________________________________________
clean:
	cd $(OBJDIR); rm -f *.o *.log *.exe *.a *.so 


# DO NOT DELETE

